package com.sell.common;

import com.sell.vo.ResultVo;
import lombok.Data;

/**
 * http返回
 * Created by megan on 2018/2/10.
 */
public class HttpResult {

    public static ResultVo success(Object object) {
        ResultVo resultVO = new ResultVo();
        resultVO.setData(object);
        resultVO.setCode(ResultEnum.SUCCESS.getCode());
        resultVO.setMsg(ResultEnum.SUCCESS.getMsg());
        return resultVO;
    }

    public static ResultVo success() {
        return success(null);
    }

    public static ResultVo errorCode(Integer code, String msg) {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        return resultVO;
    }

    public static ResultVo errorMsg(String msg) {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(ResultEnum.ERROR.getCode());
        resultVO.setMsg(msg);
        return resultVO;
    }

    public static ResultVo error() {
        ResultVo resultVO = new ResultVo();
        resultVO.setCode(ResultEnum.ERROR.getCode());
        resultVO.setMsg(ResultEnum.ERROR.getMsg());
        return resultVO;
    }

    public enum ResultEnum {
        SUCCESS(0, "成功"), ERROR(1, "失败");

        private Integer code;
        private String msg;

        ResultEnum(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }

}
